﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module.Core.BusinessLogic;
using Module.Core.BusinessLogic.ProductCart;
using Module.Core.Common;
using Module.Core.EntitiesInfo;
using Module.Core.EntitiesInfo.TablesInfo;

namespace Web.Cms.ProductCart
{
    public partial class CreateEditProductOrders : System.Web.UI.Page
    {
        #region Khai báo
        private int id = 0;
        private DataSet ds = null;
        private int orderId;
        private int status;

        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            orderId = ObjConvertUtility.ToInt32(Request.QueryString["orderId"]);
            if (!IsPostBack)
            {

                LoadData();
            }
        }


        #region FillData
        void FillData(ProductOrderInfo info)
        {
            info.OrderId = orderId;
            info.TotalPrice = decimal.Parse(txtTotalPrice.Text);
            info.TotalDealxu = float.Parse(txtTotalDealxu.Text);
            info.OrderDate = txtCreateDate.SelectedDate;
           


        }
        #endregion

        #region LoadData
        private void LoadData()
        {
            try
            {
                if (orderId > 0)
                {
                    btnUpdate.Visible = true;

                    ProductOrderInfo info = ProductOrderBL.Select(orderId);
                    if (info != null)
                    {

                        txtCreateDate.SelectedDate = info.OrderDate;
                        txtTotalPrice.Text = info.TotalPrice.ToString();
                        txtTotalDealxu.Text = info.TotalDealxu.ToString();
                        BindDropdownlist();

                    }
                }

            }
            catch (Exception ex)
            {
                lblUpdateStatus.Text = "Error: " + ex.Message;
            }
        }
        #endregion

        #region sửa
      
      

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                ProductOrderInfo info = new ProductOrderInfo();
                FillData(info);
                ProductOrderBL.Update(info);
                lblUpdateStatus.Text = "Bạn đã chỉnh sửa thành công";
            }
            catch (Exception ex)
            {
                lblUpdateStatus.Text = "Error: " + ex.Message;
            }
        }
        #endregion

        #region BindDropdownlist
        public void BindDropdownlist()
        {
            ds = ProductOrderBL.BindDropdownlist(orderId);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                ddropFullName.DataSource = ds;
                ddropFullName.DataTextField = "FullName";
                ddropFullName.DataValueField = "IdMember";
                ddropFullName.DataBind();
            }
        }

        #endregion
    }
}